# ------------------------------------------------------------------------------
# Autor:             terrasky
# Date:              2024-03-27
# Ver:               v1.0 
# ------------------------------------------------------------------------------
# _*_ coding:UTF-8 _*_
# from PyQt5.Qt import QPlainTextEdit
from PyQt5.Qt import *
from PyQt5.QtCore import pyqtSignal

class QEnterPlainTextEdit(QPlainTextEdit):
    
    returnPressed = pyqtSignal()  # 定义信号

    def keyPressEvent(self, keyEvent):
        if keyEvent.key() == Qt.Key.Key_Return:
            self.returnPressed.emit()
        else:
            return super().keyPressEvent(keyEvent)


class QMouseButtonTableWidget(QTableWidget):
    mouseMidBtnClicked = pyqtSignal()
    mouseRightBtnClicked = pyqtSignal()

    def mousePressEvent(self,mouseEvent):
        if mouseEvent.button() == Qt.MouseButton.RightButton:
            self.mouseRightBtnClicked.emit()
        elif mouseEvent.button() == Qt.MouseButton.MidButton:
            self.mouseMidBtnClicked.emit()
        else:
            return super().mousePressEvent(mouseEvent)


class QMenuTableWidget(QTableWidget):

    def __init__(self,parent=None):
        return super().__init__(parent)

    def contextMenuEvent(self, event):
        print('here',event)

    def menuItemClicked(self, action):
        # 根据点击的菜单项执行不同的操作
        if action.text() == "添加行":
            self.addRow()
        elif action.text() == "删除行":
            self.removeRow(self.currentRow())

